package io.github.tangwan.utils;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * @author tangwan
 * @version V1.0
 * created on 2021/10/20 13:38
 * @since JDK 1.8
 */
public abstract class GeoUtil {

    /**
     * 计算两个坐标点之间距离
     * @param fromLatitude
     * @param fromLongitude
     * @param toLatitude
     * @param toLongitude
     * @return
     */
    public static Double calcGeodeticCurve(Double fromLatitude, Double fromLongitude, Double toLatitude, Double toLongitude) {
        GlobalCoordinates source = new GlobalCoordinates(fromLatitude, fromLongitude);
        GlobalCoordinates target = new GlobalCoordinates(toLatitude, toLongitude);
        //对比百度地图，计算结果和Sphere坐标系计算结果一致，表明计算结果正确，WGS84坐标系的计算结果存在几十米的误差。
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target);
        return geoCurve.getEllipsoidalDistance();
    }

}
